package cn.itcast.annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 *
 */

@Pro(className = "cn.itcast.annotation.Demo1" , methodName = "show")
public class ReflectTest {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        //解析注解
        //获取该类的字节码文件对象
        Class<ReflectTest> reflectTestClass = ReflectTest.class;
        //获取注解对象
        Pro annotation = reflectTestClass.getAnnotation(Pro.class); //这句话相当于在内存中自己写了一个方法实现了这个接口 ， 然后返回值类型是属性的类型
        //调用注解对象中定义的抽象方法获取属性
        String className = annotation.className();  //注解中的属性就是抽象方法
        String methodName = annotation.methodName();

        System.out.println(className);
        System.out.println(methodName);

        Class cls = Class.forName(className);
        Method method = cls.getMethod(methodName);
        Demo1 demo1 = new Demo1();
        method.invoke(demo1) ;
    }
}
